﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iMapa.Backend.ActionPlugin;
using System.Collections;
using ActionPluginAPI;
using System.Windows.Controls;

namespace iMapa.UI.ModelView.Common
{
    public class ActionTypeViewModel
    {
        private string type;

        public ActionTypeViewModel(string type)
        {
            this.type = type;
        }

        public IActionParameters CreateParameterInstance(string mapRootPath)
        {
            IActionPlugin plugin;
            PluginHandler.getInstance().GetPlugins().TryGetValue(type, out plugin);
            if (plugin != null)
            {
                return plugin.GetNewParametersInstance(mapRootPath);
            }
            else
            {
                return null;
            }
        }


        public UserControl CreateConfigurationPanel(IActionParameters parameters)
        {
            IActionPlugin plugin;
            PluginHandler.getInstance().GetPlugins().TryGetValue(type, out plugin);
            if (plugin != null)
            {
                return plugin.GetConfigPanel(parameters);
            }
            else
            {
                return null;
            }
        }

        public string Name {
            get { 
                IActionPlugin plugin;
                PluginHandler.getInstance().GetPlugins().TryGetValue(type,out plugin);
                return plugin == null ? null : plugin.GetName();
            }
        }

        public string Type
        {
            get { return type; }
        }


        public static List<ActionTypeViewModel> CreateActionTypesList()
        {
            List<ActionTypeViewModel> result = new List<ActionTypeViewModel>();
            PluginHandler handler = PluginHandler.getInstance();
            foreach (string type in handler.GetPlugins().Keys)
            {
                result.Add(new ActionTypeViewModel(type));
            }
            return result;
        }

    }
}
